#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>

using namespace std;

int minCost(const vector<vector<int>>& costs) {
    int n = costs.size();
    int dp[110][110] = { 0 };

    for (int i = 1; i <= n; ++i)
    {
        for (int j = 1; j <= 3; ++j)
        {
            switch (j)
            {
            case 1 :
                dp[i][j] = min(dp[i - 1][2], dp[i - 1][3]) + costs[i - 1][j - 1];
                break;
            case 2:
                dp[i][j] = min(dp[1][1], dp[i - 1][3]) + costs[i - 1][j - 1];
                break;
            case 3:
                dp[i][j] = min(dp[i - 1][1], dp[i - 1][2]) + costs[i - 1][j - 1];
                break;
            }
        }
    }

    int ret = INT_MAX;
    for (int i = 1; i <= 3; ++i)
    {
        ret = min(dp[n][i], ret);
    }
    return ret;
}

int main()
{
    minCost({ {17, 2, 17}, {16, 16, 5}, { 14, 3, 19 } });
    return 0;
}